// 初始化
$(function () {
    var numCount = 0;
    $("table tbody").find("tr").find("td").each(function () {
        if ($.trim($(this).text()) != null && $.trim($(this).text()) != "") {
            numCount += 1;
        }
    });
//    if (null != $("#tab tbody").find("tr") && $("#tab tbody").find("tr").length > 0) {
//        $("#count").html($("#tab tbody").find("tr").length - 1);
//    }
});
// 编码
function encode() {
    if (confirm("确定要进行操作？")) {
        var param = prompt("请输入要编码文字...", "");
        if (null != param && "" != param) {
            alert("编码之前：" + "http://www.baidu.com?" + param + "\n" + "编码之后：" + encodeURI("http://www.baidu.com?" + param));
        }
    }
}
// 编辑
function edit(obj) {
    var val = $.trim($(obj).text());
    var str = "<input type=\"text\" ";
    str += "value=\"" + val + "\" ";
    str += "name=\"" + val + "\" ";
    str += "onblur=\"javascript:blu(this);\" ";
    str += "id=\"" + val + "\">";
    str += "</input>";
    $(obj).parents("td").html(str);
    $("#" + val + "").focus();
}
// 天气
function weather(){
	var param = prompt("请输入要查找的城市名称...", "");
	$.ajax({
		url: "user/weather.html",
		type: "post",
		data: "param=" + param,
		success:function(data){
			alert(data);
		}
	});
}
// 赋值
function blu(obj) {
    var val = $.trim($(obj).val());
    var str = "<span style=\"color: #663861;\" ";
    str += "onclick=\"javascript:edit(this);\">";
    str += "" + $(obj).val() + "";
    str += "</span>";
    if (val != $.trim($(obj).attr("id"))) {
        $.ajax({
            type: "POST",
            url: "user/dataDelete.html",
            dataType: "json",
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            data: "sequenceNo=" + $(obj).parent().attr("temp") + "&userPassword=" + val,
            success: function (data) {
                $(obj).parents("td").html(str);
            },
            error: function () {
                alert("更新失败!");
            }
        });
    } else {
        $(obj).parents("td").html(str);
    }
}
// 删除
function del(num) {
    if (confirm("确定删除该记录?")) {
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "user/userDelete.html",
            data: "sequenceNo=" + num,
            success: function (data) {
                $("a").each(function () {
                    if ($(this).attr("href").indexOf("del") > 0 && $(this).attr("href").indexOf(num) > 0) {
                        $(this).parent().parent().fadeOut().remove();
                    }
                });
            }
        });
    }
}
// 增加
function add() {
    window.location = "user/userToSave.html";
}
// 修改
function update(num) {
    window.location = "user/userDataToUpdate.action?inDto.sequenceNo=" + num;
}
// 检查
function check() {
    $.ajax({
        type: "GET",
        url: "user/dataCheck.html",
        dataType: "json",
        success: function (data) {
            alert(data);
        },
        error: function () {
            alert("检查失败");
        }
    });
}
function jsoup() {
    $.ajax({
        type: "get",
        url: "user/dataDianLan.html",
        data: "url=http://www.chinalife.com.cn/jobs/module/recruitstation/listRecruitStation.do",
        success: function (data) {
//			alert(data);
        },
        error: function () {
//			alert("error");
        }
    });
}
function success_jsonpCallback(data) {
    alert(data);
}
function vote() {
    jQuery.getJSON("http://www.shunping.gov.cn/vote/view.asp?vid=31&callback=?", function (data) {
        alert(data);
    });
//	try{
//		$.ajax({
//			type: "get",
//			async: false,
//			url: "http://www.shunping.gov.cn/vote/psvote.asp?vid=31",
//			dataType: "jsonp",
//			jsonp: "callback",
//			jsonpCallback:"success_jsonpCallback",//callback的function名称
//			success : function(json){
//				alert(json);
//			},
//			error: function(){
//				alert('fail');
//			}
//		});
//	}catch(e){
//		alert(e);
//	}
}